<!DOCTYPE html>
<html lang="en">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	String path = request.getContextPath(); 
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<head>
	<title>Moto - 编辑</title>
    <meta charset="utf-8">

    <!--
        若页面需默认用极速核，增加标签：<meta name="renderer" content="webkit">
        若页面需默认用ie兼容内核，增加标签：<meta name="renderer" content="ie-comp">
        若页面需默认用ie标准内核，增加标签：<meta name="renderer" content="ie-stand">
    -->
    <meta name="renderer" content="ie-comp">
    <meta http-equiv="X-UA-Compatible" content="IE=9;IE=EDGE">
    <meta name="viewport" content="width=device-width,minimum-scale=1,maximum-scale=1,user-scalable=no">
    <script type="text/javascript" src="../js/jquery-1.9.0.min.js"></script>
    <script type="text/javascript" src="../js/layer/layer.js"></script>
    <script type="text/javascript" src="../js/kindeditor-4.1.10/kindeditor.js"></script>
    <%--<script type="text/javascript" src="../js/parse-excel.js"></script>--%>
    <style type="text/css">
        .body_div{text-align:center;}
        .table-detail{
            text-align:center;
            border: 1px solid rgb(228,228,228);
        }
        th{
            text-align:center;
            background-color: rgb(230,230,230);
            border-bottom: 1px solid rgb(228,228,228);
            font-weight: bold;
            color:rgb(90,90,90);
            padding: 5px 8px;
        }
        td{ text-align:center;border: 1px solid rgb(228,228,228);
            padding: 5px 8px;color:rgb(56,56,56); font-size:15px;width:210px;}
        td input{ width:100%;height:1.5em; line-height:1.5em;}
        a { text-decoration: none; margin:0 1.5em;}
        textarea { width: 100%; resize: none;}
        .imgsc {width:25px;height:25px;}
        #personDetail th {width:33%;}
    </style>
</head>

<body>
<form id="motoForm" name="motoForm" action="<%=basePath%>moto/edit" method="post" enctype="multipart/form-data">
<div class="body_div" >
    <input type="hidden" name = "sid" id ="sid" value="${SRModel.sid}"/>
    <input type="hidden" name = "img_url" value="${SRModel.img_url}"/>
    <table class="table-detail" align="center">
        <tr>
            <td colspan="4" >
                <c:if test="${SRModel.sid==null || SRModel.sid==''}">
                    <strong>新增</strong>
                </c:if>
                <c:if test="${RModel.sid!=null && SRModel.sid!=''}">
                    <strong>编辑 - ${SRModel.moto_name}</strong>
                </c:if>
            </td>
        </tr>
        <tr>
            <th>名称</th>
            <td ><input name="moto_name" id="moto_name" onBlur="ajaxCkName();" value="${SRModel.moto_name}"/></td>
            <th>价格</th>
            <td><input name="moto_price" id="moto_price"  value="${SRModel.moto_price}"/></td>
        </tr>
        <tr>
            <th>类型</th>
            <td>
                <input type="hidden" name="moto_type" id="moto_type" value="${SRModel.moto_type}"/>
                <select name="moto_type_dep" id = "moto_type_dep" style="width:100%;">
                    <option value="">[请选择]</option>
                    <option value="弯梁车">弯梁车</option>
                    <option value="踏板车">踏板车</option>
                    <option value="跨骑车">跨骑车</option>
                    <option value="越野车">越野车</option>
                    <option value="跑车">跑车</option>
                    <option value="特种车">特种车</option>
                    <option value="三轮车">三轮车</option>
                    <option value="四轮车">四轮车</option>
                    <option value="助力车">助力车</option>
                    <option value="太子车">太子车</option>
                </select>
            </td>
            <th>品牌</th>
            <td><input name="moto_brand" value="${SRModel.moto_brand}"/></td>
        </tr>
        <tr>
            <th>Url</th>
            <td colspan="3"><input name="moto_url" id="moto_url" onBlur="ajaxCkUrl();" value="${SRModel.moto_url}"/></td>
        </tr>
        <tr>
            <th>图片</th>
            <td >
                <input type="file" value="选择图片" id="img_1" name="img_1"/>
            </td>
            <td style="vertical-align: middle;">
                <c:if test="${SRModel.img_url !=null and SRModel.img_url!=''}">
                    <a href="<%=basePath%>${SRModel.img_url}" target="_blank">
                        <img class="imgsc" id="imgPath1" src="<%=basePath%>${SRModel.img_url}"/>
                    </a>
                </c:if>
            </td>
            <td>
                注:重新选择图片上传可替换原图
                <%--<c:if test="${SRModel.img_url !=null and SRModel.img_url!=''}">--%>
                    <%--<a id="delImg1" href="javascript:ajaxDelImg(1,'${SRModel.img_url}');">删除</a>--%>
                <%--</c:if>--%>
            </td>
        </tr>
        <tr>
            <th colspan="4">参数列表 - <button type="button" onclick="copyExcelToTable();">粘贴Excel</button></th>
        </tr>
        <tr style="width:100%;">
            <td colspan="4" style="width:100%;">
                <table id="personDetail" class="table-detail" align="center" style="width:100%;">
                    <tbody>
                    <tr>
                        <th style="width:33%;">长×宽×高</th>
                        <td  colspan="3"><input name="cs_ckg" value="${SRModel.cs_ckg}"/></td>
                    </tr>
                    <tr>
                        <th>轴距</th>
                        <td  colspan="3"><input name="cs_zj" value="${SRModel.cs_zj}"/></td>
                    </tr>
                    <tr>
                        <th>座垫高</th>
                        <td  colspan="3"><input name="cs_zdg" value="${SRModel.cs_zdg}"/></td>
                    </tr>
                    <tr>
                        <th>离地间隙</th>
                        <td  colspan="3"><input name="cs_ldjx" value="${SRModel.cs_ldjx}"/></td>
                    </tr>
                    <tr>
                        <th>空车质量</th>
                        <td  colspan="3"><input name="cs_kczl" value="${SRModel.cs_kczl}"/></td>
                    </tr>
                    <tr>
                        <th>整备质量</th>
                        <td  colspan="3"><input name="cs_zczl" value="${SRModel.cs_zczl}"/></td>
                    </tr>
                    <tr>
                        <th>轮数</th>
                        <td  colspan="3"><input name="cs_ls" value="${SRModel.cs_ls}"/></td>
                    </tr>
                    <tr>
                        <th>轮辋</th>
                        <td  colspan="3"><input name="cs_lw" value="${SRModel.cs_lw}"/></td>
                    </tr>
                    <tr>
                        <th>前轮规格</th>
                        <td  colspan="3"><input name="cs_qlgg" value="${SRModel.cs_qlgg}"/></td>
                    </tr>
                    <tr>
                        <th>后轮规格</th>
                        <td  colspan="3"><input name="cs_hlgg" value="${SRModel.cs_hlgg}"/></td>
                    </tr>
                    <tr>
                        <th>油箱容积</th>
                        <td  colspan="3"><input name="cs_yxrj" value="${SRModel.cs_yxrj}"/></td>
                    </tr>
                    <tr>
                        <th>可选颜色</th>
                        <td  colspan="3"><input name="cs_kxys" value="${SRModel.cs_kxys}"/></td>
                    </tr>
                    <tr>
                        <td colspan="4">发动机参数</td>
                    </tr>
                    <tr>
                        <th>发动机型号</th>
                        <td  colspan="3"><input name="fdj_xh" value="${SRModel.fdj_xh}"/></td>
                    </tr>
                    <tr>
                        <th>燃油类型</th>
                        <td  colspan="3"><input name="fdj_rylx" value="${SRModel.fdj_rylx}"/></td>
                    </tr>
                    <tr>
                        <th>缸数</th>
                        <td  colspan="3"><input name="fdj_gs" value="${SRModel.fdj_gs}"/></td>
                    </tr>
                    <tr>
                        <th>冲程</th>
                        <td  colspan="3"><input name="fdj_cc" value="${SRModel.fdj_cc}"/></td>
                    </tr>
                    <tr>
                        <th>冷却方式</th>
                        <td  colspan="3"><input name="fdj_lqfs" value="${SRModel.fdj_lqfs}"/></td>
                    </tr>
                    <tr>
                        <th>最大功率</th>
                        <td  colspan="3"><input name="fdj_zdgl" value="${SRModel.fdj_zdgl}"/></td>
                    </tr>
                    <tr>
                        <th>排量</th>
                        <td  colspan="3"><input name="fdj_pl" value="${SRModel.fdj_pl}"/></td>
                    </tr>
                    <tr>
                        <th>压缩比</th>
                        <td  colspan="3"><input name="fdj_ysb" value="${SRModel.fdj_ysb}"/></td>
                    </tr>
                    <tr>
                        <th>最大扭矩</th>
                        <td  colspan="3"><input name="fdj_zdnj" value="${SRModel.fdj_zdnj}"/></td>
                    </tr>
                    <tr>
                        <th>供油方式</th>
                        <td  colspan="3"><input name="fdj_gyfs" value="${SRModel.fdj_gyfs}"/></td>
                    </tr>
                    <tr>
                        <th>经济油耗</th>
                        <td  colspan="3"><input name="fdj_jjyh" value="${SRModel.fdj_jjyh}"/></td>
                    </tr>
                    <tr>
                        <th>环保标准</th>
                        <td  colspan="3"><input name="fdj_hbbz" value="${SRModel.fdj_hbbz}"/></td>
                    </tr>
                    <tr>
                        <td colspan="4">其他参数</td>
                    </tr>
                    <tr>
                        <th>制动方式</th>
                        <td  colspan="3"><input name="qt_zdfs" value="${SRModel.qt_zdfs}"/></td>
                    </tr>
                    <tr>
                        <th>启动方式</th>
                        <td  colspan="3"><input name="qt_qdfs" value="${SRModel.qt_qdfs}"/></td>
                    </tr>
                    <tr>
                        <th>离合器形式</th>
                        <td  colspan="3"><input name="qt_lhqxs" value="${SRModel.qt_lhqxs}"/></td>
                    </tr>
                    <tr>
                        <th>变速器形式</th>
                        <td  colspan="3"><input name="qt_bsqxs" value="${SRModel.qt_bsqxs}"/></td>
                    </tr>
                    <tr>
                        <th>整车质保</th>
                        <td  colspan="3"><input name="qt_zczb" value="${SRModel.qt_zczb}"/></td>
                    </tr>
                    <tr>
                        <th>最高车速</th>
                        <td  colspan="3"><input name="qt_zgss" value="${SRModel.qt_zgss}"/></td>
                    </tr>
                    <tr>
                        <th>最大载重</th>
                        <td  colspan="3"><input name="qt_zdzz" value="${SRModel.qt_zdzz}"/></td>
                    </tr>
                    <tr>
                        <td colspan="4">其他配置</td>
                    </tr>
                    <tr>
                        <th>前大灯</th>
                        <td  colspan="3"><input name="pz_qdd" value="${SRModel.pz_qdd}"/></td>
                    </tr>
                    <tr>
                        <th>后尾灯</th>
                        <td  colspan="3"><input name="pz_hwd" value="${SRModel.pz_hwd}"/></td>
                    </tr>
                    <tr>
                        <th>改装配置</th>
                        <td  colspan="3"><input name="pz_gzpz" value="${SRModel.pz_gzpz}"/></td>
                    </tr>
                    <tr>
                        <th>减震器</th>
                        <td  colspan="3"><input name="pz_zzq" value="${SRModel.pz_zzq}"/></td>
                    </tr>
                    <tr>
                        <th>消声器</th>
                        <td  colspan="3"><input name="pz_xsq" value="${SRModel.pz_xsq}"/></td>
                    </tr>
                    <tr>
                        <th>仪表盘</th>
                        <td  colspan="3"><input name="pz_ybp" value="${SRModel.pz_ybp}"/></td>
                    </tr>
                    <tr>
                        <th>储物箱</th>
                        <td  colspan="3"><input name="pz_cwx" value="${SRModel.pz_cwx}"/></td>
                    </tr>
                    <tr>
                        <th>轮胎</th>
                        <td  colspan="3"><input name="pz_lt" value="${SRModel.pz_lt}"/></td>
                    </tr>
                    <tr>
                        <th>其他</th>
                        <td  colspan="3"><input name="pz_qt" value="${SRModel.pz_qt}"/></td>
                    </tr>



                    </tbody>
                </table>

            </td>
        </tr>
        <tr>
            <th style="width:15%;">备注</th>
            <td colspan="3">
                <textarea rows="8" name="moto_remark" id="moto_remark">${SRModel.moto_remark}</textarea>
            </td>
        </tr>

        <tr>
            <td colspan="4">
                <a href="javascript:editSave();">[保存]</a>
                <a href="javascript:window.close();">[关闭]</a>
                <%--<a href="javascript:history.go(-1);">[返回]</a>--%>
            </td>
        </tr>

    </table>
</div>

</form>
</body>
<script type="text/javascript">
    window.onload=function(){

        $("#moto_type_dep").val("${SRModel.moto_type}");
    };

    function editSave(){
        $("#moto_type").val($("#moto_type_dep").find("option:selected").val());
        ajaxCkName();
        if(!moto_name_flag){
            layer.msg("该名称已存在");
            $("#moto_name").focus();
            return ;
        }
        ajaxCkUrl();
        if(!moto_url_flag){
            layer.msg("该Url已存在");
            $("#moto_url").focus();
            return ;
        }
        document.motoForm.action ="<%=basePath%>moto/save";
        document.motoForm.submit();
    }

    function copyExcelToTable() {
        parseExcelToTableText('personDetail', function(parseDatas){
            if (parseDatas[0].length < 1) {
                alert('复制的数据格式不正确，请确认后再试！');
                return false;
            }
            return true;
        }, function(tableEl, parseDatas){
            // 处理结束回调
        });
    }

    var moto_name_flag = false;
    function ajaxCkName(){
        var sid = $("#sid").val();
        var moto_name = $("#moto_name").val();
        if(moto_name==""){
            return ;
        }
        $.ajax({
            type:"POST",
            url:"<%=basePath%>ajax/ck/name",
            data:{
                'sid' : sid,
                'moto_name' : moto_name,
                'tm':new Date().getTime()
            },
            dataType:'json',
            cache: false,
            async: false,
            success: function(data){
                if(data.code==0){
                    moto_name_flag = true;//可用
                }else{
                    moto_name_flag = false;
                    layer.msg("该型号名称已存在");
                }
            }, error: function(XMLHttpRequest, textStatus, errorThrown) {
                alert(XMLHttpRequest.status+" | "+XMLHttpRequest.readyState+"|"+textStatus);
            }
        });
    }

    var moto_url_flag = false;
    function ajaxCkUrl(){
        var sid = $("#sid").val();
        var moto_url = $("#moto_url").val();
        if(moto_url==""){
            return ;
        }
        $.ajax({
            type:"POST",
            url:"<%=basePath%>ajax/ck/url",
            data:{
                'sid' : sid,
                'moto_url' : moto_url,
                'tm':new Date().getTime()
            },
            dataType:'json',
            cache: false,
            async: false,
            success: function(data){
                if(data.code==0){
                    moto_url_flag = true;//可用
                }else{
                    moto_url_flag = false;
                    layer.msg("该Url已存在");
                }
            }, error: function(XMLHttpRequest, textStatus, errorThrown) {
                alert(XMLHttpRequest.status+" | "+XMLHttpRequest.readyState+"|"+textStatus);
            }
        });
    }


    function parseExcelToTableText(tableId, validationFn, callback)
    {
        if(clipboardDate_ = window.clipboardData==undefined){
            alert("请切换至IE浏览器7~9版本,F12");
        }
        var clipboardDate_ = window.clipboardData.getData("text");
        if (!clipboardDate_) {
            alert('对不起，Excel剪贴板中没有内容!');
            return;
        }
        // 解析excel数据
        var rows = clipboardDate_.split('\r\n');
        var parseDatas = [];
        $.each(rows , function(index, item){
            if(index < rows.length && index<45){
                if (item != ''){
                    var cols = item.split('\t');
                    parseDatas.push(cols);
                } else {
                    parseDatas.push("-");
                }
            }
        });
        // 校验解析数据有效性
        // 校验数据有效性
        if (parseDatas.length == 0)
        {
            alert('请先复制数据！');
            return false;
        }
        if (validationFn)
            if (!validationFn(parseDatas))
                return;
        // 填入数据并插入表单
        $.each(parseDatas, function(index ,item){
            var trCount =  $('#' + tableId + ' tbody tr').length;
            if (index > trCount - 1)
            {
                var trs = $('#' + tableId + ' tbody tr');
                var cloneTr;

                // 克隆表格行，如果表格无行则尝试从模板克隆
                if (trs.length > 0)
                    cloneTr = $(trs[0]).clone();
                else {
                    cloneTr = $($('#' + tableId + 'Template tbody tr')[0]).clone();
                    if (!cloneTr[0]) {
                        alert('出错了，找不到对应的模板');
                        return;
                    }
                }


                $('#' + tableId + ' tbody').append(cloneTr);
                $(':text', cloneTr).each(function(i, item){
                    this.value = parseDatas[index][i+1] || '';
                });
                $('td:eq(1)', cloneTr).text(index + 1);
            } else
            {
                $(':text', $('#' + tableId + ' tbody tr:eq(' + index + ')')).each(function(i, item){
                    this.value = parseDatas[index][i+1] || '';
                });

                $('td:eq(1)',  $('#' + tableId + ' tbody tr:eq(' + index + ')')).text(index + 1);
            }
        });
        // 回调函数
        callback($('#' + tableId), parseDatas);
    }

    var editor;
    KindEditor.ready(function(K) {
        editor= K.create('textarea[name="moto_remark"]', {
            uploadJson : '<%=basePath %>/js/kindeditor-4.1.10/jsp/upload_json.jsp',
            fileManagerJson : '<%=basePath %>/js/kindeditor-4.1.10/jsp/file_manager_json.jsp',
            allowFileManager : true,
            allowImageUpload : true,
            autoHeightMode : true,
            afterCreate : function() {this.loadPlugin('autoheight');},
            afterBlur : function(){ this.sync(); }  //Kindeditor下获取文本框信息
        });
    });

</script>
</html> 

